const {
  getOrderInfo,
  updatePrice,
  completeOrder,
} = require('../../apiConfig/apiList/luban')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    formData:{},
    disabled: false,
    orderId: '',

  },
  getDetail(){
    let that = this;
    let params = {id: this.data.orderId}
    getOrderInfo(params).then(res=>{
      console.log(res)
      if(res.code == 200){
        that.setData({
          formData: res.data
        });
      }
    })
  },
  handlePrice(){
    let that = this;
    let params = {
      id: this.data.orderId,
      repairedPrice: this.data.formData.repairedPrice,
    };
    console.log('params', params)
    updatePrice(params).then(res=>{
      if(res.code == 200){
        wx.showToast({
          title: '报价成功',
          icon: 'success',
          mask: true
        })
        that.backPage();
      }
    })
  },
  handleComplete(){
    let that = this;
    let params = {
      id: this.data.orderId,
    };
    completeOrder(params).then(res=>{
      console.log(res);
      if(res.code == 200){
        wx.showToast({
          title: '处理完成',
          icon: 'success',
          mask: true,
        })
        that.backPage();
      }
    })
  },
  getPrice(e){
    console.log('getPrice', e)
    let value = e.detail.value;
    this.setData({
      'formData.repairedPrice': value
    })
  },
  backPage(){
    wx.redirectTo({
      url: '/pages/order-list/index',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    this.setData({
      orderId: options.id
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getDetail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})